package top.huanyv.tools.utils;

import java.lang.reflect.Array;
import java.util.function.Function;

/**
 * @author huanyv
 * @date 2023/11/27 16:42
 */
public class ArrayUtil {

    public static <S, T> T[] map(S[] source, Class<T> target, Function<S, T> function) {
        T[] result = (T[]) Array.newInstance(target, source.length);
        for (int i = 0; i < source.length; i++) {
            T apply = function.apply(source[i]);
            result[i] = apply;
        }
        return result;
    }


}
